#ifndef REFLEX_INL
#define REFLEX_INL

#include <string>
#include <unordered_map>
#include <functional>
#include "task/abstract_task.h"
#include "task/task_factory.h"
#include "type_exception.hpp"

namespace reflex
{
template<class T>
void TaskReflexManager::registerTaskType(const std::string &type_name)
{
    if (!std::is_base_of_v<task::AbstractTask, T>)
    {
        throw TypeTraitsException("register type must inherit AbstractTask");
    }
    if (!std::is_constructible_v<T, std::string>)
    {
        throw TypeTraitsException("register type must have construction T(std::string) or T(const std::string&) ");
    }
    if (isTypeRegistered(type_name))
    {
        throw TypeTraitsException(std::string("type [") + type_name + std::string("] duplicate definition"));
    }
    task_type type_construction = std::bind(task::TaskFactory<T>::template createTask<std::string>, std::placeholders::_1);
    saveType(type_name, type_construction);
}

template<class T>
void TaskReflexManager::unregisterTaskType(const std::string &type_name)
{
    if (isTypeRegistered(type_name))
    {
        removeType(type_name);
    }
}
}


#endif //REFLEX_INL
